﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<html>
<head>
	<title></title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

	<script src="../../js/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
		html, body {
			margin: 0;
			padding: 0;
			border: 0;
			width: 100%;
			height: 100%;
			overflow: hidden;
		}
	</style>

</head>
<body>
	<div class="mini-panel" title="项目信息列表" style="width:100%;height:100%;"
		bodyStyle="padding: 0;">
	<div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
		<table style="width: 100%;">
			<tr>	
                <td style="width:100%;">
                    <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                    <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>       
					<a class="mini-button" iconCls="icon-upload" onclick="toUpload()">上传</a>
                </td>
            
				<td style="white-space: nowrap;">
					<label style="font-family: Verdana;">编码: </label> 	<input id="code" class="mini-textbox"  style="width:80px;"/>
					<label style="font-family: Verdana;">名称: </label> 	<input id="name" class="mini-textbox" style="width:80px;"/>
					<label style="font-family: Verdana;">所属部门: </label> 	<input id="project" class="mini-textbox" style="width:80px;"/>
					<!-- <label style="font-family: Verdana;">编写时间: </label> 	<input id="createTime" class="mini-datepicker" style="width:100px;"/> -->
					<a class="mini-button" iconCls="icon-search" plain="true" onclick="onSearch()">查询</a>
				</td>
			</tr>
		</table>
	</div>
	<!--撑满页面-->
	<div class="mini-fit">

		<div id="datagrid1" class="mini-datagrid" showPager="false"
			style="width: 100%; height: 100%;" idField="id" multiSelect="true"
		>
			<div property="columns">
				 <div type="checkcolumn" ></div>
				<div field="code" width="80" headerAlign="center" allowSort="true">项目编码</div>
				<div field="name" width="100" headerAlign="center" allowSort="true">项目名称</div>
				<!-- <div field="type" width="100" headerAlign="center" allowSort="true" renderer="onDocTypesRenderer" >文档类型</div> -->
				<div field="projectName" width="100" align="center" headerAlign="center">所属部门</div>
<!-- 				<div field="createTime" width="100" dateFormat="yyyy-MM-dd HH:mm:ss" allowSort="true" >编写时间</div> -->
				<div field="level" width="100" allowSort="true" renderer="onLevelRenderer">保密级别</div>

				<div field="act" width="100" headerAlign="center" allowSort="false" 
					align="center" renderer="onActionRenderer">操作</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
		var userType = '<%= session.getAttribute("userType")%>';
		var userId = '<%= session.getAttribute("userId")%>';
		if(userType == 3) {//管理员
			$("td:first").hide();
		}
		mini.parse();
		var grid = mini.get("datagrid1");
		grid.setUrl("/document/doc/docInfoList.do");
		grid.load({level:userType,userId:userId});
		//查询
		function onSearch() {
			var data = {};
			if(userType){
				data['level']=userType
			}
			var code = mini.get("code").getValue();
			var name = mini.get("name").getValue();
			var project = mini.get("project").getValue();
			var createDate = mini.get("createTime").getFormValue();
			if(code) data['code'] = code;
			if(name) data['name'] = name;
			if(project) data['projectName'] = project;
			if(createDate) data['createDate'] = createDate;
			grid.load(data);
		}
		
		//文档新增
        function add() {
            mini.open({
                targetWindow: window,
                url:"docAdd.jsp",
                title: "文档信息添加", 
                width: 600, height: 300,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new" };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }
		//删除文档信息
        function remove() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.id);
                    }
                    var id = ids.join(',');
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "/document/doc/deleteDocInfo.do?id=" +id,
                        success: function (text) {
                            grid.reload();
                        },
                        error: function () {
                        }
                    });
                }
            } else {
                alert("请选中一条记录");
            }
        }
		//上传文档信息页面
        function toUpload() {
            var rows = grid.getSelecteds();
            if (rows.length == 1) {
	            mini.open({
	                targetWindow: window,
	                url:"upload.jsp",
	                title: "各版本文档上传页", 
	                width: 600, height: 300,
	                onload: function () {
	                    var iframe = this.getIFrameEl();
	                    var data = { action: "upload",id: rows[0].id };
	                    iframe.contentWindow.SetData(data);
	                },
	                ondestroy: function (action) {
	                    grid.reload();
	                }
	            });
            }else if(rows.length < 1) {
            	alert("请选中一条记录");
            } else {
                alert("只能选中一条记录");
            }
        }
        //渲染按钮
        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record._uid;
            var rowIndex = e.rowIndex;
	
            var s = '<a class="New_Button" href="javascript:onShow('+record.id+',\''+record.name+'\')">查看文档</a> &nbsp;&nbsp;'
            	/* s += '<a class="New_Button" href="javascript:onHistory('+record.id+',\''+record.name+'\')">历史查看</a>' */
            return s;
        }
        function onShow(id,name) {
        	
            var win = mini.open({
                targetWindow: window,
                url:"showDoc.jsp",
                title: "文档查看", 
                width: 600, height: 300,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "showDoc",id: id,name:name};
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
            win.max();
        }
        //历史查看
        function onHistory(id,name) {
            var win = mini.open({
                targetWindow: window,
                url:"history.jsp",
                title: "各版本文档列表页", 
                width: 600, height: 300,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "history",id: id,name:name };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
            win.max();
        }
        ///////////////////////////////////////////////////////
        var Levels = [{ id: 1, text: '一星' }, { id: 2, text: '二星'}, { id: 3, text: '三星'}];
        function onLevelRenderer(e) {
            for (var i = 0, l = Levels.length; i < l; i++) {
                var g = Levels[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        }
        ///////////////////////////////////////////////////////
        var docTypes = [{ "id": "usa", "text": "开发进度周报" }, { "id": "cn", "text": "项目开发总结" },{ "id": "a", "text": "软件需求与开发计划" }, 
			{ "id": "b", "text": "可行性分析" },
			{ "id": "c", "text": "项目开发计划" },
			{ "id": "d", "text": "需求规格说明书" },
			{ "id": "e", "text": "综合测试报告" },
			{ "id": "f", "text": "软件设计说明书" },
			{ "id": "g", "text": "系统设计说明书" },
			{ "id": "h", "text": "使用说明书" }];
        function onDocTypesRenderer(e) {
            for (var i = 0, l = docTypes.length; i < l; i++) {
                var g = docTypes[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        }
</script>

</body>
</html>